//                        date: [[20120714223937]]
//                        Author: Ahmed Fathi Hamouda Abd El Hafez
using System;
using System.ComponentModel;
using System.Reflection;
using System.Data;
using StoresManagementDataLayer;
using System.Collections.Generic;


namespace StoresManagementBusinessLayer
{

    /// <summary>
    ///  Business Object OF Table ProductClassifications
    /// </summary>

    public partial class BLProductClassification : INotifyPropertyChanged
    {
        #region Fields
        private BLProductClassification.BusinessRelatedObjects f_RelatedObjects = null;
        #endregion

        #region properties
        /// <summary>
        /// keys object of BLProductClassification
        /// </summary>
        [Browsable(false)]
        public BLProductClassification.BusinessRelatedObjects RelatedObjects
        {
            get
            {
                if (this.f_RelatedObjects == null)
                {
                    this.f_RelatedObjects = new BusinessRelatedObjects(this);
                }
                return f_RelatedObjects;
            }
            set
            {
                f_RelatedObjects = value;
            }
        }
        #endregion

        #region RelatedObjects
        /// <summary>
        /// contains properties of the Related Objects 
        /// </summary>
        [Serializable]
        public partial class BusinessRelatedObjects
        {
            private BLProductClassification containerObject = null;
            private Dictionary<string, string> RelatedObjectsMappings = new Dictionary<string, string>();

            private BLProductClassification f_ObjectOfProductClassification_ParentID = null;

            /// <summary>
            /// returns the BLProductClassification Object that Corresponds to ProductClassification_ParentID property
            /// </summary>
            public BLProductClassification ObjectOfProductClassification_ParentID
            {
                get
                {
                    if (this.f_ObjectOfProductClassification_ParentID == null)
                    {
                        this.f_ObjectOfProductClassification_ParentID = new BLProductClassification();
                        if (containerObject.ProductClassification_ParentID != null)
                        {
                            this.f_ObjectOfProductClassification_ParentID.ProductClassification_ID = containerObject.ProductClassification_ParentID;
                            this.f_ObjectOfProductClassification_ParentID.LoadByProperties(new string[] { BLProductClassification.PropertiesNames.ProductClassification_ParentID });
                        }
                    }
                    return this.f_ObjectOfProductClassification_ParentID;
                }
            }

            public BusinessRelatedObjects(BLProductClassification item)
            {
                this.containerObject = item;
                if (this.containerObject != null)
                {
                    this.containerObject.PropertyChanged += new PropertyChangedEventHandler(this.containerObject_PropertyChanged);
                    this.containerObject.AfterLoad += new EventHandler(this.containerObject_AfterLoad);
                }
                RelatedObjectsMappings.Add(BLProductClassification.PropertiesNames.ProductClassification_ParentID, "f_ObjectOfProductClassification_ParentID");
            }
            public void ResetProperties(string[] propertiesNames)
            {
                for (int i = 0; i < propertiesNames.Length; i++)
                {
                    if (this.RelatedObjectsMappings.ContainsKey(propertiesNames[i]))
                    {
                        string FieldName = this.RelatedObjectsMappings[propertiesNames[i]];
                        this.GetType().GetField(FieldName, BindingFlags.NonPublic).SetValue(this, null);
                    }
                }
            }

            private void containerObject_PropertyChanged(object sender, PropertyChangedEventArgs e)
            {
                this.ResetProperties(new string[] { e.PropertyName });
            }
            private void containerObject_AfterLoad(object sender, EventArgs e)
            {
                string[] propertiesNames = new string[this.RelatedObjectsMappings.Keys.Count];
                this.RelatedObjectsMappings.Keys.CopyTo(propertiesNames, 0);
                this.ResetProperties(propertiesNames);
            }

        }
        #endregion

    }
}
